<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/taglib.jsp" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>编辑${displayName}</title>
		<link rel="stylesheet" href="${r'${staticPath}'}/admin/tcsf/reset.css" />
		<link href="${r'${staticPath}'}/admin/iconfont/iconfont.css" type="text/css" rel="stylesheet" />
		<link rel="stylesheet" href="${r'${staticPath}'}/admin/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${r'${staticPath}'}/admin/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" />
		<link rel="stylesheet" href="${r'${staticPath}'}/admin/tcsf/tcsf.panel.css" />
		<link rel="stylesheet" href="${r'${staticPath}'}/admin/tcsf/content.css" />

		<script src="${r'${staticPath}'}/admin/tcsf/jquery.min.js"></script>
		<script src="${r'${staticPath}'}/admin/lib/jquery.form/jquery.form.min.js"></script>
		<script src="${r'${staticPath}'}/admin/lib/jquery.form/jquery.validate.min.js"></script>
		<script src="${r'${staticPath}'}/admin/lib/jquery.form/jquery.validate.extend.js"></script>
		<script src="${r'${staticPath}'}/admin/lib/jquery.form/messages_zh.js"></script>
		<script type="text/javascript" src="${r'${staticPath}'}/admin/lib/bootstrap-3.3.7-dist/js/bootstrap.min.js" ></script>
		<script type="text/javascript" src="${r'${staticPath}'}/admin/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" ></script>
		<script type="text/javascript" src="${r'${staticPath}'}/admin/tcsf/content.js" ></script>
	</head>
	<body>

		<div class="create-page tpanel">
			<div class="panel-content">
				<div class="container-fluid">
			
					<form id="createForm" class="form-horizontal">
						<input type="hidden" name="id" value="${r'${entity.id}'}" />
						<#list fields as field>  
							<#if field.formField>
						
						<#if field.inputType == "密码">
						<div class="form-group<#if field_index == 0> form-group-first</#if>">
							<label for="${field.propertyName}" class="col-sm-2 control-label">${field.displayName}</label>
							<div class="col-sm-8">
							<input class="form-control" 
							<#if field.isPlainPassword()>
								type="text"
							<#else>
								type="password"
							</#if> 
								id="${field.propertyName}" name="${field.propertyName}" 
							<#if field.allowNull>
								placeholder="请输入${field.displayName}" 
							<#else>  
								placeholder="请输入${field.displayName}(必填)" required 
							</#if> 
								minlength="${field.min}" maxlength="${field.max}" 
								/>
							</div>
						</div>
						<#if field.isConfirmPassword()>
						<div class="form-group">
							<label for="${field.propertyName}Confirm" class="col-sm-2 control-label">确认${field.displayName}</label>
							<div class="col-sm-8">
							<input class="form-control" 
							<#if field.isPlainPassword()>
								type="text"
							<#else>
								type="password"
							</#if> 
								id="${field.propertyName}Confirm" name="${field.propertyName}Confirm" 
								placeholder="请再次输入${field.displayName}" 
								equalTo="#${field.propertyName}"
								/>
							</div>
						</div>
						</#if>
						<#else>
						<div class="form-group<#if field_index == 0> form-group-first</#if>">
							<label for="${field.propertyName}" class="col-sm-2 control-label">${field.displayName}</label>
							<div class="col-sm-8">
							<#if field.jdbcDataType == "Date">
								<input type="text" class="form-control datetimepicker"  <#if field.isReadonly()>readonly</#if>  
									id="${field.propertyName}" name="${field.propertyName}" 
									value='<fmt:formatDate value="${r'${entity.'}${field.propertyName}}" pattern="${field.timeFormat}" />' 
								<#if field.allowNull>
									placeholder="请输入${field.displayName}" 
								<#else>  
									placeholder="请输入${field.displayName}(必填)" required 
								</#if> 
									/>
							</#if>
							<#if field.inputType == "文件上传">
								<input class="form-control" type="file" 
									id="${field.propertyName}" name="${field.propertyName}" 
								<#if field.allowNull>
									placeholder="请上传文件${field.displayName}" 
								<#else>  
									placeholder="请上传文件${field.displayName}(必需)" required 
								</#if> 
									/>
							</#if>
							<#if field.inputType == "富文本">
								<textarea class="form-control" 
									id="${field.propertyName}" name="${field.propertyName}" 
								<#if field.allowNull>
									placeholder="请输入${field.displayName}" 
								<#else>  
									placeholder="请输入${field.displayName}(必填)" required 
								</#if> 
									>
								</textarea>
							</#if>
							<#if field.inputType == "文本">
								<input type="text" class="form-control" <#if field.isReadonly()>readonly</#if> 
									id="${field.propertyName}" name="${field.propertyName}" 
									value="${r'${entity.'}${field.propertyName}}" 
									<#if field.subInputType == "邮箱">
									email="true"
									</#if>
									<#if field.subInputType == "手机">
									isMobile="true"
									</#if>
									<#if field.subInputType == "身份证">
									isIdCardNo="true"
									</#if>
									<#if field.regExp != "">
									${field.propertyName}Valid="true"
									</#if>
									<#if field.allowNull>
										placeholder="请输入${field.displayName}" 
									<#else>  
										placeholder="请输入${field.displayName}(必填)" required 
									</#if> 
									minlength="${field.min}" maxlength="${field.max}" 
									<#if field.unique>
										remote="${r'${ctx}'}${controllerUrl}/exist?id=${r'${entity.id}'}&property=${field.propertyName}" 
									</#if> 
									/>
							</#if>
							<#if field.inputType == "数值">
								<input type="number" class="form-control"  <#if field.isReadonly()>readonly</#if> 
									id="${field.propertyName}" name="${field.propertyName}" 
									value="${r'${entity.'}${field.propertyName}}" 
									<#if field.subInputType == "小数">
									number="true"
									<#elseif field.subInputType == "整数">
									digits="true"
									</#if>
									<#if field.allowNull>
										placeholder="请输入${field.displayName}" 
									<#else>  
										placeholder="请输入${field.displayName}(必填)" required 
									</#if> 
									min="${field.min}" max="${field.max}" 
									/>
							</#if>
							</div>
						</div>
						</#if>
							</#if>
						</#list>  
					  	
					  	<div class="form-group">
							<div class="col-sm-12" style="text-align: center;">
								<a class="btn btn-default" href="javascript:window.history.back();">返回</a>
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input type="submit" class="btn btn-primary" value="保存" />
							</div>
					  	</div>
					  	
					</form>
				
				</div>
			</div>
		</div>
		<script type="text/javascript">
			window.parent.changeTitle('编辑${displayName}');
			$(function() {
				// 身份证号码验证 
				jQuery.validator.addMethod("isIdCardNo", function(value, element) { 
					var idcardRule = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
					return this.optional(element) || idcardRule.test(value);  
				}, "请正确输入您的身份证号码"); 

				// 手机号码验证 
				jQuery.validator.addMethod("isMobile", function(value, element) { 
				  var length = value.length; 
				  var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/; 
				  return this.optional(element) || (length == 11 && mobile.test(value)); 
				}, "请正确填写您的手机号码"); 

				// 电话号码验证 
				jQuery.validator.addMethod("isTel", function(value, element) { 
				  var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678 
				  return this.optional(element) || (tel.test(value)); 
				}, "请正确填写您的电话号码"); 

				// 联系电话(手机/电话皆可)验证 
				jQuery.validator.addMethod("isPhone", function(value,element) { 
				  var length = value.length; 
				  var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/; 
				  var tel = /^\d{3,4}-?\d{7,9}$/; 
				  return this.optional(element) || (tel.test(value) || mobile.test(value)); 

				}, "请正确填写您的联系电话"); 

				// 邮政编码验证 
				jQuery.validator.addMethod("isZipCode", function(value, element) { 
				  var tel = /^[0-9]{6}$/; 
				  return this.optional(element) || (tel.test(value)); 
				}, "请正确填写您的邮政编码"); 
				
				<#list fields as field>
				<#if field.regExp != "">
				jQuery.validator.addMethod("${field.propertyName}Valid", function(value, element) { 
				  var tel = ${field.regExp}; 
				  return this.optional(element) || (tel.test(value)); 
				}, "您的输入不正确"); 
				</#if>
				</#list>
				
				
				
                $('#createForm').validate({
                    focusCleanup:true,
					focusInvalid:false,
                    errorClass: "unchecked",
                    validClass: "checked",
                    errorElement: "span",
                    submitHandler:function(form){
                        $(form).ajaxSubmit({
                            type:"post",
                            url:"${r'${ctx}'}${controllerUrl}/update",
                            beforeSubmit: function() {
								window.parent.layer.load();
							},
                            success: function(r) {
                                var resp = $.parseJSON(r);
                                window.parent.layer.closeAll('loading');
                                if(resp.code == 'OK') {
                                    window.location.href = '${r'${ctx}'}${controllerUrl}';
                                    window.parent.layer.msg('保存成功', {icon: 1});
                                }else {
                                    window.parent.layer.msg(resp.message, {icon: 2});
                                }
							}
                        });
                        return false;
                    },
                    errorPlacement:function(error,element){
                        var s = element.parent().find("span[htmlFor='" + element.attr("id") + "']");
                        if(s!=null){
                            s.remove();
                        }
                        error.appendTo(element.parent());
                    },
                    success: function(label) {
                        label.removeClass("unchecked").addClass("checked");
                    }
                });
				
				$('.datetimepicker').datetimepicker({format:'yyyy-mm-dd hh:ii:ss'});
			});
		</script>
	</body>
</html>
